package com.ninghushangbao.ninghu.controller;

import com.ninghushangbao.ninghu.controller.vo.ResultEntity;
import com.ninghushangbao.ninghu.entity.Company;
import com.ninghushangbao.ninghu.service.CompanyService;
import com.ninghushangbao.ninghu.utils.BaseResult.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/company")
@CrossOrigin()
public class CompanyController {

    @Autowired
    CompanyService companyService;

    /*
    * 后台查询
    * */
    @GetMapping("/sel_all")
    public ResultEntity getCompany(){
        return ResultUtil.success(companyService.selectCompany());
    }
    /*
    * 后台新增
    * */
    @PostMapping("/cp_add")
    public ResultEntity addCompany(@RequestBody Company company){
        System.out.println(company);
        companyService.addCompany(company);
        return ResultUtil.success();
    }
    /*
    * 后台修改
    * */
    @PutMapping("/cp_mod")
    public ResultEntity updateCompany(@RequestBody Company company){
        System.out.println(company);
        companyService.updateCompany(company);
        return ResultUtil.success();
    }
    /*
    * 后台删除
    * */
    @DeleteMapping("/cp_del")
    public ResultEntity deleteCompany(@RequestBody List<Integer> companyId){
        companyService.deleteCompanyById(companyId);
        return ResultUtil.success();
    }

}
